{% extends 'iframe/basePlus.html.twig' %}
{% block search %}
    <div class="layui-fluid">
        <div class="layui-row">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-header">搜索</div>
                    <div class="layui-card-body">
                        <form class="layui-form" onsubmit="return false;">
                            <dry-common role="select" label="表单类型" name="dry_form_type" value="" variable="formTypeData"></dry-common>
                            <dry-common role="submit" submit="确定" reset="重置"></dry-common>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
{% endblock %}
{% block cardHeader %}
    列表<a href="/Admin/Field/new" class="layui-btn layui-btn-sm" style="float:right;margin-top:6px;">添加</a>
{% endblock %}
{% block cardBody %}
    <script type="text/html" id="toolbar">
        <div class="layui-btn-container">
            <button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="gDelete">批量删除</button>
            <button class="layui-btn layui-btn-sm" lay-event="gOperate">高级操作</button>
        </div>
    </script>
    <script type="text/html" id="bar">
        <a class="layui-btn layui-btn-xs" lay-event="show">查看</a>
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="delete">删除</a>
    </script>
    <table class="layui-hide" id="list" lay-filter="list"></table>
    <script>
        function getIndexColumn()
        {
            var list = [
                {
                    title: 'ID',
                    field: 'id',
                    width: ID_WIDTH
                },
                {
                    title: '名称',
                    field: 'dry_name',
                    width: WIDTH_180
                },
                {
                    title: '字段',
                    field: 'dry_field',
                    width: WIDTH_180
                },
                {
                    title: '字段类型',
                    field: 'dry_field_type',
                    width: WIDTH_250,
                    templet: function(rs){return mergeRequest("tag", "dry_field_type", rs.dry_field_type, "/Api/FieldType/getList", "", 1);}
                },
                {
                    title: '是否主键字段',
                    field: 'dry_is_primary',
                    width: WIDTH_130,
                    templet: function(rs){return mergeRequest("tag", "dry_is_primary", rs.dry_is_primary, "/Api/Choice/getListByKey?key=yesNo", "", 1);}
                },
                {
                    title: '默认值',
                    field: 'dry_default'
                },
                {
                    title: '表单默认值',
                    field: 'dry_form_default'
                },
                {
                    title: '状态',
                    field: 'dry_status',
                    width: STATUS_WIDTH,
                    templet: function(rs){return mergeRequest("tag", "dry_status", rs.dry_status, "/Api/Choice/getListByKey?key=status", "", 1);}
                },
                {
                    title: '备注',
                    field: 'dry_note'
                },
                {
                    title: 'placeholder',
                    field: 'dry_placeholder',
                    hide: true
                },
                {
                    title: '排序',
                    field: 'dry_sort',
                    width: SORT_WIDTH
                },
                {
                    title: '添加时间',
                    field: 'dry_add_time',
                    width: ADD_TIME_WIDTH
                },
                {
                    title: '表单类型',
                    field: 'dry_form_type',
                    templet: function(rs){return mergeRequest("tag", "dry_form_type", rs.dry_form_type, "/Api/Choice/getListByKey?key=formType", "", 1);}
                },
                {
                    title:'操作',
                    toolbar: '#bar',
                    width: OPERATE_WIDTH
                }
            ];
            return list;
        }

        layui.use(['dry', 'jquery'], function(dry, $){
            var f = {};

            /*批量删除*/
            f.gDelete = function(object, checkStatus)
            {
                console.log(object);
                console.log(checkStatus);
            };

            /*即时编辑*/
            f.immediatelyEdit = function(object)
            {
                console.log(object);
            };

            /*表格渲染结束*/
            f.done = function(response, currentPage, count)
            {
                dry.mergeRequest();
            };

            /*查看按钮*/
            f.show = function(object, id)
            {
                window.location.href = "/Admin/Field/show?id=" + id;
            };

            /*编辑按钮*/
            f.edit = function(object, id)
            {
                window.location.href = "/Admin/Field/edit?id=" + id;
            };

            /*搜索*/
            f.search = function()
            {
                return {
                    'formType': $("#dry_form_type").val()
                };
            };

            function isReady()
            {
                if($("dry-common[name='dry_form_type']").attr("ok") == "1"){
                    return true;
                }
                return false;
            }

            function list()
            {
                var result = dry.list("/Api/Field/index", getIndexColumn(), 100, f);
                config = result.config;
                instance = result.instance;
            }

            var config = null;
            var instance = null;

            dry.runAfter(isReady, list);

            $("button[type='submit']").click(function(){
                config.page = {"curr": 1};
                config.where = f['search']();
                instance.reload(config);
            });
        });
    </script>
{% endblock %}